// pages/cartype/cartype.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    carType: [
      { name: '大通14座', img: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1078754866,687630975&fm=26&gp=0.jpg', checked: false },
      { name: '金龙17座', img: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1078754866,687630975&fm=26&gp=0.jpg', checked: false },
      { name: '宇通20座', img: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1585109942979&di=f0b4b807715f4d6bc3a937f64d1c29bd&imgtype=0&src=http%3A%2F%2Fpic3.gtobal.com%2Fsells%2F20150617%2F582796067f6f11e275c5bc5444b1dcf5.jpg', checked: false },
      { name: '金旅30座', img: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1078754866,687630975&fm=26&gp=0.jpg', checked: false },
      { name: '金旅40座', img: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1078754866,687630975&fm=26&gp=0.jpg', checked: false },
      { name: '申龙46座', img: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1078754866,687630975&fm=26&gp=0.jpg', checked: false },
    ],
    carTypeSelect: ''
  },

  carTypeOk: function (e) {
    let _that = this 
    let pages = getCurrentPages(); 
    let prevPage = pages[pages.length - 2];
    prevPage.setData({ 
      carTypeSelect: _that.data.carTypeSelect
    })
    wx.navigateBack({
      delta: 1  
    })
  },
  cartTypeSelect: function (e) {
    let _that = this
    _that.setData({
      carTypeSelect: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let _that = this
    let carTypeSelect = options.carTypeSelect
    _that.data.carType.forEach((item,index) => {
      if(item.name === carTypeSelect) {
        let param = 'carType['+index+'].checked'
        _that.setData({
          [param]: true,
          carTypeSelect: item.name
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})